package xuedou.skymoni.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ResourceBundle;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;

import xuedou.skymoni.impl.ExamImpl;
import xuedou.skymoni.service.ExamService;
import xuedou.skymoni.util.Encoding;

/**
 * 成绩查询
 * @author Jinmingming Jinmingming@xuedou.com
 * @date 2013-3-21
 */
public class ResultServlet extends HttpServlet {

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		ExamService examService = new ExamImpl();
		response.setContentType("text/html");
		response.setCharacterEncoding("UTF-8");
		response.setHeader("Cache-Control", "no-cache");
		PrintWriter out = response.getWriter();
		String action = request.getParameter("action");
		if(action.equalsIgnoreCase("selectScore")){
			String sname = Encoding.codeUTF8(request.getParameter("sname")).replaceAll(" ","");
			String ticknum = Encoding.codeUTF8(request.getParameter("ticknum")).replaceAll(" ","");
			String examnum = Encoding.codeUTF8(request.getParameter("examnum")).replaceAll(" ","");
			String[] result = examService.selectScore(sname, ticknum,examnum);
			if(result==null){
				out.print("NoMessage");
			}else{
				JSONArray array = JSONArray.fromObject(result);
				out.print(array);
			}
			out.flush();
			out.close();
		}
	}

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doPost(request, response);
	}
}
